﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using tjerkocr2;
using System.Diagnostics;

namespace tjerkgui
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void load_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;
            Image inputImage;
            Bitmap inputBitmap;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                inputImage = Image.FromFile(openFileDialog1.FileName);
                inputPictureBox.Image = inputImage;
                inputBitmap = (Bitmap)inputImage;
                double[] OCRresultsPercentages = new double[36];

                
                tjerkocr2.TestOCRAlgorithm tocr2 = new tjerkocr2.TestOCRAlgorithm("tjerkocr");
                removeBorders rb = new removeBorders();
                inputBitmap = rb.crop(inputBitmap);
                inputPictureBox.Image = (Image)inputBitmap;

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                OCRresultsPercentages = tocr2.DoOCR(inputBitmap);
                stopwatch.Stop();
                ocrCandidatesTextBox.Clear();
                ocrCandidatesTextBox.AppendText("time: " + stopwatch.ElapsedMilliseconds + "ms\n");
                for (int i = 0; i < OCRresultsPercentages.Length; i++)
                {
                    ocrCandidatesTextBox.AppendText(tocr2.indexToCharacter(i) + " " + OCRresultsPercentages[i] + "\n");
                }
            }

        }
    }
}
